package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.NotebookEntity;
import com.company.project.service.NotebookService;



/**
 * notebook
 *
 * @author lee
 * @email ligore2100@gmail.com
 * @date 2025-03-23 17:44:24
 */
@Controller
@RequestMapping("/")
public class NotebookController {
    @Autowired
    private NotebookService notebookService;

    /**
    * 跳转到页面
    */
    @GetMapping("/index/notebook")
    public String notebook() {
        return "notebook/list";
    }


    @ApiOperation(value = "查询分页数据")
    @PostMapping("notebook/listByPage")
    @SaCheckPermission("notebook:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody NotebookEntity notebook){
        LambdaQueryWrapper<NotebookEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
//        queryWrapper.eq(tbGoods.getId() != null, NotebookEntity::getId, notebook.getId());
        queryWrapper.orderByDesc(NotebookEntity::getId);
        IPage<NotebookEntity> iPage = notebookService.page(notebook.getQueryPage(), queryWrapper);
        return DataResult.success(iPage);
    }


    @ApiOperation(value = "新增")
    @PostMapping("notebook/add")
    @SaCheckPermission("notebook:add")
    @ResponseBody
    public DataResult add(@RequestBody NotebookEntity notebook){
            notebookService.save(notebook);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("notebook/delete")
    @SaCheckPermission("notebook:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
            notebookService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("notebook/update")
    @SaCheckPermission("notebook:update")
    @ResponseBody
    public DataResult update(@RequestBody NotebookEntity notebook){
            notebookService.updateById(notebook);
        return DataResult.success();
    }



}
